home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tads110.zip / STD.T < prev    next >
Text File  |  1990-05-12  |  13KB  |  379 lines

  1. /* Copyright (c) 1989 by Michael J. Roberts.  All Rights Reserved. */
  2. /*
  3. Name
  4.   std.t5   - standard default adventure definitions
  5. Function
  6.   Provides standard definitions for the objects and functions that are
  7.   required by TADS, but not defined in the file "adv.t5".  Generally,
  8.   the author will wish to replace these definitions with his own in a
  9.   finished game, but these definitions will suffice for getting the
  10.   game up and running.
  11. Notes
  12.   If you are including this file in your game, you must also include
  13.   the general adventure definitions file, "adv.t5".
  14.   
  15.   Do not include this file in your game if you wish to replace the
  16.   objects and functions defined here.
  17. Modified
  18.   03/04/89 MJRoberts     - created
  19. */
  20.  
  21. /*
  22.  *   Pre-declare all functions, so the compiler knows they are functions.
  23.  *   (This is only really necessary when a function will be referenced
  24.  *   as a daemon or fuse before it is defined; however, it doesn't hurt
  25.  *   anything to pre-declare all of them.)
  26.  */
  27. die: function;
  28. scoreRank: function;
  29. init: function;
  30. terminate: function;
  31. pardon: function;
  32. sleepDaemon: function;
  33. eatDaemon: function;
  34. darkTravel: function;
  35. setlamps: function;
  36.  
  37. /*
  38.  *   The die() function is called when the player dies.  It tells the
  39.  *   player how well he has done (with his score), and asks if he'd
  40.  *   like to start over (the alternative being quitting the game).
  41.  */
  42. die: function
  43. {
  44.     "\b*** You have died ***\b";
  45.     scoreRank();
  46.     "\bYou may restore a saved game, start over, or quit.";
  47.     while ( 1 )
  48.     {
  49.         local resp;
  50.  
  51.     "Please enter RESTORE, RESTART, or QUIT: >";
  52.         resp := upper(input());
  53.         if ( resp = 'RESTORE' )
  54.     {
  55.         resp := askfile( 'File to restore' );
  56.         if ( resp = nil ) "Restore failed. ";
  57.         else if ( restore( resp )) "Restore failed. ";
  58.         else
  59.         {
  60.             setscore( global.score, global.turnsofar );
  61.         abort;
  62.         }
  63.     }
  64.         else if ( resp = 'RESTART' )
  65.     {
  66.         setscore( 0, 0 );
  67.             restart();
  68.     }
  69.     else if ( resp = 'QUIT' )
  70.         {
  71.         terminate();
  72.             quit();
  73.         abort;
  74.         }
  75.     }
  76. }
  77.  
  78. /*
  79.  *   The scoreRank() function displays how well the player is doing.
  80.  *   This default definition doesn't do anything aside from displaying
  81.  *   the current and maximum scores.  Some game designers like to
  82.  *   provide a ranking that goes with various scores ("Novice Adventurer,"
  83.  *   "Expert," and so forth); this is the place to do so if desired.
  84.  *
  85.  *   Note that "global.maxscore" defines the maximum number of points
  86.  *   possible in the game; change the property in the "global" object
  87.  *   if necessary.
  88.  */
  89. scoreRank: function
  90. {
  91.     "In a total of "; say( global.turnsofar );
  92.     " turns, you have achieved a score of ";
  93.     say( global.score ); " points out of a possible ";
  94.     say( global.maxscore ); ".\n";
  95. }
  96.  
  97. /*
  98.  *   The init() function is run at the very beginning of the game.
  99.  *   It should display the introductory text for the game, start
  100.  *   any needed daemons and fuses, and move the player's actor ("Me")
  101.  *   to the initial room, which defaults here to "startroom".
  102.  */
  103. init: function
  104. {
  105.     // put introductory text here
  106.     
  107.     version.sdesc;                // display the game's name and version number
  108.  
  109.     setdaemon( turncount, nil );               // start the turn counter daemon
  110.     setdaemon( sleepDaemon, nil );                    // start the sleep daemon
  111.     setdaemon( eatDaemon, nil );                     // start the hunger daemon
  112.     Me.location := startroom;                // move player to initial location
  113.     startroom.lookAround( true );                    // show player where he is
  114. }
  115.  
  116. /*
  117.  *   preinit() is called after compiling the game, before it is written
  118.  *   to the binary game file.  It performs all the initialization that can
  119.  *   be done statically before storing the game in the file, which speeds
  120.  *   loading the game, since all this work has been done ahead of time.
  121.  *
  122.  *   This routine puts all lamp objects (those objects with islamp = true) into
  123.  *   the list global.lamplist.  This list is consulted when determining whether
  124.  *   a dark room contains any light sources.
  125.  */
  126. preinit: function
  127. {
  128.     local o;
  129.     
  130.     global.lamplist := [];
  131.     o := firstobj();
  132.     while( o <> nil )
  133.     {
  134.         if ( o.islamp ) global.lamplist := global.lamplist + o;
  135.         o := nextobj( o );
  136.     }
  137. }
  138.  
  139. /*
  140.  *   The terminate() function is called just before the game ends.  It
  141.  *   generally displays a good-bye message.  The default version does
  142.  *   nothing.  Note that this function is called only when the game is
  143.  *   about to exit, NOT after dying, before a restart, or anywhere else.
  144.  */
  145. terminate: function
  146. {
  147. }
  148.  
  149. /*
  150.  *   The pardon() function is called any time the player enters a blank
  151.  *   line.  The function generally just prints a message ("Speak up" or
  152.  *   some such).  This default version just says "I beg your pardon?"
  153.  */
  154. pardon: function
  155. {
  156.     "I beg your pardon? ";
  157. }
  158.  
  159. /*
  160.  *   This function is a daemon, started by init(), that monitors how long
  161.  *   it has been since the player slept.  It provides warnings for a while
  162.  *   before the player gets completely exhausted, and causes the player
  163.  *   to pass out and sleep when it has been too long.  The only penalty
  164.  *   exacted if the player passes out is that he drops all his possessions.
  165.  *   Some games might also wish to consider the effects of several hours
  166.  *   having passed; for example, the time-without-food count might be
  167.  *   increased accordingly.
  168.  */
  169. sleepDaemon: function( parm )
  170. {
  171.     local a, s;
  172.  
  173.     global.awakeTime := global.awakeTime + 1;
  174.     a := global.awakeTime;
  175.     s := global.sleepTime;
  176.  
  177.     if ( a = s or a = s+10 or a = s+20 )
  178.         "\bYou're feeling a bit drowsy; you should find a
  179.         comfortable place to sleep. ";
  180.     else if ( a = s+25 or a = s+30 )
  181.         "\bYou really should find someplace to sleep soon, or
  182.         you'll probably pass out from exhaustion. ";
  183.     else if ( a >= s+35 )
  184.     {
  185.       global.awakeTime := 0;
  186.       if ( Me.location.isbed or Me.location.ischair )
  187.       {
  188.         "\bYou find yourself unable to stay awake any longer.
  189.         Fortunately, you are ";
  190.         if ( Me.location.isbed ) "on "; else "in ";
  191.         Me.location.adesc; ", so you gently slip off into
  192.         unconsciousness.
  193.         \b* * * * *
  194.         \bYou awake some time later, feeling refreshed. ";
  195.       }
  196.       else
  197.       {
  198.         local itemRem, thisItem;
  199.  
  200.         "\bYou find yourself unable to stay awake any longer.
  201.         You pass out, falling to the ground.
  202.         \b* * * * *
  203.         \bYou awaken, feeling somewhat the worse for wear.
  204.         You get up and dust yourself off. ";
  205.         itemRem := Me.contents;
  206.         while (car( itemRem ))
  207.         {
  208.             thisItem := car( itemRem );
  209.             if ( not thisItem.isworn )
  210.             thisItem.moveInto( Me.location );
  211.             itemRem := cdr( itemRem );
  212.         }
  213.       }
  214.     }
  215. }
  216.  
  217. /*
  218.  *   This function is a daemon, set running by init(), which monitors how
  219.  *   long it has been since the player has had anything to eat.  It will
  220.  *   provide warnings for some time prior to the player's expiring from
  221.  *   hunger, and will kill the player if he should go too long without
  222.  *   heeding these warnings.
  223.  */
  224. eatDaemon: function( parm )
  225. {
  226.     local e, l;
  227.  
  228.     global.lastMealTime := global.lastMealTime + 1;
  229.     e := global.eatTime;
  230.     l := global.lastMealTime;
  231.  
  232.     if ( l = e or l = e+5 or l = e+10 )
  233.         "\bYou're feeling a bit peckish. Perhaps it would be a good
  234.         time to find something to eat. ";
  235.     else if ( l = e+15 or l = e+20 or l = e+25 )
  236.         "\bYou're feeling really hungry. You should find some food
  237.         soon or you'll pass out from lack of nutrition. ";
  238.     else if ( l=e+30 or l = e+35 )
  239.         "\bYou can't go much longer without food. ";
  240.     else if ( l >= e+40 )
  241.     {
  242.         "\bYou simply can't go on any longer without food. You perish from
  243.         lack of nutrition. ";
  244.         die();
  245.     }
  246. }
  247.  
  248. /*
  249.  *   The numObj object is used to convey a number to the game whenever
  250.  *   the player uses a number in his command.  For example, "turn dial
  251.  *   to 621" results in an indirect object of numObj, with its "value"
  252.  *   property set to 621.
  253.  */
  254. numObj: object              // when a number is used in a player command,
  255.     value = 0               //  this is set to its value
  256.     sdesc = "that"
  257.     adesc = "that"
  258.     thedesc = "that"
  259.     verDoTypeOn( actor, io ) = {}
  260.     doTypeOn( actor, do ) = { "\"Tap, tap, tap, tap...\" "; }
  261.     verIoTurnTo( actor ) = {}
  262.     ioTurnTo( actor, do ) = { do.doTurnTo( actor, self ); }
  263. ;
  264.  
  265. /*
  266.  *   strObj works like numObj, but for strings.  So, a player command of
  267.  *     type "hello" on the keyboard
  268.  *   will result in a direct object of strObj, with its "value" property
  269.  *   set to the string 'hello'.
  270.  *
  271.  *   Note that, because a string direct object is used in the save, restore,
  272.  *   and script commands, this object must handle those commands.
  273.  */
  274. strObj: object              // when a string is used in a player command,
  275.     value = ''              //  this is set to its value
  276.     sdesc = "that"
  277.     adesc = "that"
  278.     thedesc = "that"
  279.     verDoTypeOn( actor, io ) = {}
  280.     doTypeOn( actor, io ) = { "\"Tap, tap, tap, tap...\" "; }
  281.     verDoSave( actor ) = {}
  282.     doSave( actor ) =
  283.     {
  284.         if (save( self.value ))
  285.             "Save failed. ";
  286.         else
  287.             "Saved. ";
  288.     abort;
  289.     }
  290.     verDoRestore( actor ) = {}
  291.     doRestore( actor ) =
  292.     {
  293.         if (restore( self.value ))
  294.             "Restore failed. ";
  295.         else
  296.     {
  297.             "Restored. ";
  298.         setscore( global.score, global.turnsofar );
  299.     }
  300.         abort;
  301.     }
  302.     doScript( actor ) =
  303.     {
  304.         logging( self.value );
  305.         "Writing script to "; say( self.value ); ".\n";
  306.         abort;
  307.     }
  308.     doSay( actor ) =
  309.     {
  310.         "Okay, \""; strObj.value; "\".";
  311.     }
  312. ;
  313.  
  314. /*
  315.  *   The "global" object is the dumping ground for any data items that
  316.  *   don't fit very well into any other objects.  The properties of this
  317.  *   object that are particularly important to the objects and functions
  318.  *   are defined here; if you replace this object, but keep other parts
  319.  *   of this file, be sure to include the properties defined here.
  320.  *
  321.  *   Note that awakeTime is set to zero; if you wish the player to start
  322.  *   out tired, just move it up around the sleepTime value (which specifies
  323.  *   the interval between sleeping).  The same goes for lastMealTime; move
  324.  *   it up to around eatTime if you want the player to start out hungry.
  325.  *   With both of these values, the player only starts getting warnings
  326.  *   when the elapsed time (awakeTime, lastMealTime) reaches the interval
  327.  *   (sleepTime, eatTime); the player isn't actually required to eat or
  328.  *   sleep until several warnings have been issued.  Look at the eatDaemon
  329.  *   and sleepDaemon functions for details of the timing.
  330.  */
  331. global: object
  332.     turnsofar = 0                            // no turns have transpired so far
  333.     score = 0                            // no points have been accumulated yet
  334.     maxscore = 100                                    // maximum possible score
  335.     verbose = nil                             // we are currently in TERSE mode
  336.     awakeTime = 0               // time that has elapsed since the player slept
  337.     sleepTime = 400     // interval between sleeping times (longest time awake)
  338.     lastMealTime = 0              // time that has elapsed since the player ate
  339.     eatTime = 200         // interval between meals (longest time without food)
  340.     lamplist = []              // list of all known light providers in the game
  341. ;
  342.  
  343. /*
  344.  *   The "version" object defines, via its "sdesc" property, the name and
  345.  *   version number of the game.  Change this to a suitable name for your
  346.  *   game.
  347.  */
  348. version: object
  349.     sdesc = "A TADS Adventure
  350.       \n Developed with TADS, the Text Adventure Development System.\n";
  351. ;
  352.  
  353. /*
  354.  *   "Me" is the player's actor.  Pick up the default definition, basicMe,
  355.  *   from "adv.t".
  356.  */
  357. Me: basicMe
  358. ;
  359.  
  360. /*
  361.  *   darkTravel() is called whenever the player attempts to move from a dark
  362.  *   location into another dark location.  By default, it just says "You
  363.  *   stumble around in the dark," but it could certainly cast the player into
  364.  *   the jaws of a grue, whatever that is...
  365.  */
  366. darkTravel: function
  367. {
  368.     "You stumble around in the dark, and don't get anywhere. ";
  369. }
  370.  
  371. /*
  372.  *   goToSleep - carries out the task of falling asleep.  We just display
  373.  *   a message to this effect.
  374.  */
  375. goToSleep: function
  376. {
  377.     "***\bYou wake up some time later, feeling refreshed. ";
  378. }
  379.